/**
 * 
 */
package classexercise;

/**
 * @author qingke
 *
 */
public class Account {
	private String id;
	private String name;
	private int balance=0;
	
	public Account(String id,String name){
		this.id=id;
		this.name=name;
	}
	public Account(String id,String name,int balance){
		this.id=id;
		this.name=name;
		this.balance=balance;
	}

	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getBalance() {
		return balance;
	}
	public void setBalance(int balance) {
		this.balance = balance;
	}
	
	public int credit(int amount){
		   return balance +=amount;
	}
	public int debit(int amount){
		    if(amount<=balance){
		    	balance-=amount;
		    }
		    else{
		    	System.out.println("Amount exceeded balance");
		    }
		    return balance;
	}
	
	public int transferTo(Account another,int amount){
		   if(amount<=balance){
			     this.debit(amount);
			     //this.balance -= amount;
			     another.credit(amount);
		   }
		   else{
			   System.out.println("Amount excceded balance");
		   }
		   return balance;
	}
	public String toString(){
		String d="Account[id="+id+",name="+name+",balace="+balance+"]";
		return d;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
         Account ac=new Account("345","cxy"); 
         Account ac1=new Account("34","cx",6455);
         System.out.println(ac.toString());
         System.out.println(ac1.toString());
         ac1.transferTo(ac, 5300);
         System.out.println(ac.toString());
         System.out.println(ac1.toString());
	}

}
